package cn.fay.chapter11;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class Demo2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Random random=new Random(47);
		
		List<Integer> integers=new ArrayList<Integer>();
		for (int i = 0; i < 10; i++) {
			integers.add(random.nextInt(100));
		}
		//Collections.addAll(integers, 0,1,2,3,4,5,6,7,8,9,10);
		//integers.addAll(Arrays.asList(0,1,2,3,4,5,6,7,8,9,10));
		System.out.println("1: "+integers);
		Integer I1=new Integer(11);
		integers.add(I1);
		System.out.println("2: "+integers);
		System.out.println("3: "+integers.contains(I1));
		integers.remove(I1);
		Integer I2=integers.get(2);
		System.out.println("4: "+I2+" "+integers.indexOf(I2));
		List<Integer> sub=integers.subList(1, 4);
		System.out.println("sub "+sub);
		System.out.println(integers.containsAll(sub));
		Collections.sort(sub);
		System.out.println("sorted sub: "+sub);
		System.out.println(integers.containsAll(sub));
		Collections.shuffle(sub, random);
		System.out.println("shuffled sublist :"+sub);
		System.out.println(integers.containsAll(sub));
		List<Integer> copy=new ArrayList<Integer>(integers);
		System.out.println("copy: "+copy);
		copy.addAll(7, sub);
		System.out.println("copy addall "+copy);
		//integers.clear();
		//System.out.println(integers);
		//System.out.println(integers.isEmpty());
//		copy.retainAll(sub);
//		System.out.println(copy);
		copy.removeAll(sub);
		System.out.println(copy);
		
	}

}
